<html>
<head>
<title>AJAX - Hello World</title>
<script src="ajax.js" language="javascript"></script>
<script>
var receiveReq = getXmlHttpRequestObject();

function sayHello()
{

//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		//Setup the connection as a GET call to SayHello.html.
		//True explicity sets the request to asyncronous (default).
		receiveReq.open("GET", 'SayHello.html', true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = handleSayHello; 
		//Make the actual request.
		receiveReq.send(null);
	}
}

function handleSayHello()
{
    //Check to see if the XmlHttpRequests state is finished.
	if (receiveReq.readyState == 4) {
		//Set the contents of our span element to the result of the asyncronous call.
		document.getElementById('hello').innerHTML = receiveReq.responseText;
	}
}
</script>
</head>

<body>
<a href="javascript:sayHello();">Say Hello!</a>
<span id="hello"></span>
</body>
</html>
